class Solution
{
public:
    int numberOfSubarrays(vector<int> &nums, int k)
    {
        int oddCount = 0;
        unordered_map<int, int> oddPrefixCount;
        oddPrefixCount[0] = 1;
        int result = 0;
        int n = nums.size();
        for (int i = 0; i < n; ++i)
        {
            if (nums[i] & 1)
            {
                ++oddCount;
            }
            if (oddCount >= k)
            {
                result += oddPrefixCount[oddCount - k];
            }
            ++oddPrefixCount[oddCount];
        }
        return result;
    }
};